Fix IndexOutOfBoundsException crash in SurfaceMountingManager.addViewAt (#57172)#57172
Open
cipolleschi wants to merge 1 commit into
Open
Fix IndexOutOfBoundsException crash in SurfaceMountingManager.addViewAt (#57172)#57172cipolleschi wants to merge 1 commit into
cipolleschi wants to merge 1 commit into
Conversation
|
@cipolleschi has exported this pull request. If you are a Meta employee, you can view the originating Diff in D108081522. |
…At (react#57172) Summary: `SurfaceMountingManager.addViewAt()` crashes with `IndexOutOfBoundsException` when the Fabric mount instruction buffer specifies an insertion index that exceeds the parent `ViewGroup` child count. This occurs due to a timing race between asynchronous mount instruction generation and actual view hierarchy state — a preceding removal or independent mutation can leave the parent with fewer children than the instruction expects. The fix handles `IndexOutOfBoundsException` gracefully by clamping the index to `parentView.childCount` (appending at the end) and logging a soft exception for diagnostics. This matches the established recovery pattern already used in this file for analogous timing races: - `removeViewAt` gracefully handles mismatched indices by finding the real index - `addViewAt` already handles missing `viewState` with soft exception + early return - `addViewAt` already handles views with existing parents by removing and re-adding Changelog: [Android][Fixed] - Fix `IndexOutOfBoundsException` crash in Fabric `SurfaceMountingManager.addViewAt` when mount instruction index exceeds parent child count Differential Revision: D108081522
1ec1321 to
0accf45
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
SurfaceMountingManager.addViewAt()crashes withIndexOutOfBoundsExceptionwhen the Fabric mount instruction buffer specifies an insertion index that exceeds the parentViewGroupchild count. This occurs due to a timing race between asynchronous mount instruction generation and actual view hierarchy state — a preceding removal or independent mutation can leave the parent with fewer children than the instruction expects.The fix handles
IndexOutOfBoundsExceptiongracefully by clamping the index toparentView.childCount(appending at the end) and logging a soft exception for diagnostics. This matches the established recovery pattern already used in this file for analogous timing races:removeViewAtgracefully handles mismatched indices by finding the real indexaddViewAtalready handles missingviewStatewith soft exception + early returnaddViewAtalready handles views with existing parents by removing and re-addingChangelog:
[Android][Fixed] - Fix
IndexOutOfBoundsExceptioncrash in FabricSurfaceMountingManager.addViewAtwhen mount instruction index exceeds parent child countDifferential Revision: D108081522